﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using BusinessObjects;

namespace DataAccess.SqlServer
{
    public class SqlServerHopDong: IHopDong
    {
        public int Insert(HopDong hopDong)
        {
            string sql = @" Insert into HopDong(SoHopDong, NgayKy, ChucVuNguoiKy, NguoiKy, NguoiLaoDong, DiaDiemLamViec, ChucDanhChuyenMon, LoaiHopDong)
                            Values(@SoHopDong, @NgayKy, @ChucVuNguoiKy, @NguoiKy, @NguoiLaoDong, @DiaDiemLamViec, @ChucDanhChuyenMon, @LoaiHopDong)";

            SqlParameter[] param = {
                                       new SqlParameter("@SoHopDong", hopDong.SoHopDong),
                                       new SqlParameter("@NgayKy", hopDong.NgayKy),
                                       new SqlParameter("@ChucVuNguoiKy", hopDong.ChucVuNguoiKy.Oid),
                                       new SqlParameter("@NguoiKy", hopDong.NguoiKy.Oid),
                                       new SqlParameter("@NguoiLaoDong", hopDong.NguoiLaoDong.Oid),
                                       new SqlParameter("@DiaDiemLamViec", hopDong.DiaDiemLamViec.Oid),
                                       new SqlParameter("@ChucDanhChuyenMon", hopDong.ChucDanhChuyenMon),
                                       new SqlParameter("@LoaiHopDong", hopDong.LoaiHopDong)
                                   };
            return DataProvider.Insert(sql, true, param);
            
        }

        public int Update(HopDong hopDong)
        {
            string sql = @" Update HopDong
                            Set SoHopDong = @SoHopDong, 
                                NgayKy = @NgayKy, 
                                ChucVuNguoiKy = @ChucVuNguoiKy, 
                                NguoiKy = @NguoiKy, 
                                NguoiLaoDong = @NguoiLaoDong, 
                                DiaDiemLamViec = @DiaDiemLamViec, 
                                ChucDanhChuyenMon = @ChucDanhChuyenMon, 
                                LoaiHopDong = @LoaiHopDong
                            Where Oid = @Oid";

            SqlParameter[] param = {
                                       new SqlParameter("@Oid", hopDong.Oid),
                                       new SqlParameter("@SoHopDong", hopDong.SoHopDong),
                                       new SqlParameter("@NgayKy", hopDong.NgayKy),
                                       new SqlParameter("@ChucVuNguoiKy", hopDong.ChucVuNguoiKy.Oid),
                                       new SqlParameter("@NguoiKy", hopDong.NguoiKy),
                                       new SqlParameter("@NguoiLaoDong", hopDong.NguoiLaoDong),
                                       new SqlParameter("@DiaDiemLamViec", hopDong.DiaDiemLamViec),
                                       new SqlParameter("@ChucDanhChuyenMon", hopDong.ChucDanhChuyenMon),
                                       new SqlParameter("@LoaiHopDong", hopDong.LoaiHopDong)
                                   };
            return DataProvider.Update(sql, param);
        }

        public int Delete(HopDong hopDong)
        {
            string sql = @" Delete From HopDong Where Oid = @Oid";

            SqlParameter param = new SqlParameter("@Oid", hopDong.Oid);

            return DataProvider.Update(sql, param);
        }


        public int Save(HopDong obj)
        {
            throw new NotImplementedException();
        }
    }
}
